package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teach.domain.NbChapter;
import com.ruoyi.teach.domain.NbCourse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbCheck;
import com.ruoyi.teach.service.INbCheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核标准Controller
 * 
 * @author ruoyi
 * @date 2022-01-07
 */
@RestController
@RequestMapping("/teach/check")
public class NbCheckController extends BaseController
{
    @Autowired
    private INbCheckService nbCheckService;

    /**
     * 查询考核标准列表
     */
    @PreAuthorize("@ss.hasPermi('teach:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbCheck nbCheck)
    {
        startPage();
        List<NbCheck> list = nbCheckService.selectNbCheckList(nbCheck);
        return getDataTable(list);
    }

    /**
     * 导出考核标准列表
     */
    @PreAuthorize("@ss.hasPermi('teach:check:export')")
    @Log(title = "考核标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbCheck nbCheck)
    {
        List<NbCheck> list = nbCheckService.selectNbCheckList(nbCheck);
        ExcelUtil<NbCheck> util = new ExcelUtil<NbCheck>(NbCheck.class);
        util.exportExcel(response, list, "考核标准数据");
    }

    /**
     * 获取考核标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbCheckService.selectNbCheckById(id));
    }

    /**
     * 新增考核标准
     */
    @PreAuthorize("@ss.hasPermi('teach:check:add')")
    @Log(title = "考核标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbCheck nbCheck)
    {
        nbCheckService.insertNbCheck(nbCheck);
        return AjaxResult.success(nbCheck);
    }

    /**
     * 修改考核标准
     */
    @PreAuthorize("@ss.hasPermi('teach:check:edit')")
    @Log(title = "考核标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbCheck nbCheck)
    {
        nbCheckService.updateNbCheck(nbCheck);
        return AjaxResult.success(nbCheck);
    }

    /**
     * 删除考核标准
     */
    @PreAuthorize("@ss.hasPermi('teach:check:remove')")
    @Log(title = "考核标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbCheckService.deleteNbCheckByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('teach:check:list')")
    @GetMapping("/getcheck")
    public AjaxResult getCheck(NbCourse nbCourse){  
        return AjaxResult.success(nbCheckService.getCheck(nbCourse));
    }
}
